#!/usr/bin/env python
import py_trees


def main() -> None:
    # 1.黑板-默认命名空间
    blackboard = py_trees.blackboard.Client(name="Blackboard")
    blackboard.register_key(key="dude", access=py_trees.common.Access.WRITE)
    blackboard.register_key(key="/dudette", access=py_trees.common.Access.WRITE)
    blackboard.register_key(key="/foo/bar/wow", access=py_trees.common.Access.WRITE)
    print(blackboard)
    blackboard.dude = "Bob"
    blackboard.dudette = "Jade"
    blackboard.foo.bar.wow = "foobar"
    print(py_trees.display.unicode_blackboard())

    # 2.黑板-带命名空间
    foo = py_trees.blackboard.Client(name="Foo", namespace="foo")
    foo.register_key(key="awesome", access=py_trees.common.Access.WRITE)
    foo.register_key(key="/brilliant", access=py_trees.common.Access.WRITE)
    foo.register_key(key="/foo/clever", access=py_trees.common.Access.WRITE)
    print(foo)
    foo.awesome = True
    foo.set("/brilliant", False)
    # foo.brilliant = False # NG, 带有'/'的namespace的key，不能直接访问
    foo.clever = True
    print(py_trees.display.unicode_blackboard(client_filter={foo.unique_identifier}))


if __name__ == "__main__":
    main()

""" 1.黑板-默认命名空间
Blackboard Client
  Client Data
    write             : {'/foo/bar/wow', '/dudette', '/dude'}
    read              : set()
    name              : Blackboard
    exclusive         : set()
    unique_identifier : dd768911-dc8c-4bad-99db-bb0c9047d6a8
    namespace         : /
  Variables
    /dude        : -
    /dudette     : -
    /foo/bar/wow : -

Blackboard Data
    /dude       : Bob
    /dudette    : Jade
    /foo/bar/wow: foobar
"""

""" 2.黑板-带命名空间
Blackboard Client
  Client Data
    write             : {'/foo/clever', '/foo/awesome', '/brilliant'}
    read              : set()
    name              : Foo
    exclusive         : set()
    unique_identifier : acc84098-889a-4349-befc-bd6da4007624
    namespace         : /foo
  Variables
    /foo/awesome : -
    /brilliant   : -
    /foo/clever  : -

Blackboard Data
  Filter: {UUID('acc84098-889a-4349-befc-bd6da4007624')}
    /brilliant  : False
    /foo/awesome: True
    /foo/clever : True
"""
